'use strict';

const Service = require('egg').Service;
class ClassificationService extends Service {

    /**
   * 分类
   */
  async classify() {
    const { app } = this;
    const {[0]:category} = await app.knex.raw(`select * from pp_category`);
    let classify = []
    for(let father of category){
        if(father.upid===0){
            let cate =[]
            for(let child of category){
                if(child.upid!==0&&father.cid===child.upid){
                    cate.push(
                        {
                            cid:child.cid ,
                            name:child.name,
                        }
                    )
                }
            }
            classify.push({
                cid:father.cid ,
                name:father.name,
                cate
            })
        }
    }
    return classify
  }
}

module.exports = ClassificationService;
